from Tkinter import *
import tkMessageBox
rootwin = Tk()
rootwin.withdraw()
#print tkMessageBox.askyesno("Leave edit without saving?",
#                            "Do you want to exit edit mode\nwithout saving changes?",
#                            default=tkMessageBox.NO,icon=tkMessageBox.QUESTION)
ix = 640; iy = 480
x = ix; y = iy
resizebox = Tk()
#resizebox.protocol("WM_DELETE_WINDOW",resizebox.destroy)
resizebox.title("Resize Image")
fbox = Frame(resizebox); fbox.pack(fill=X,side=TOP,padx=20,pady=20)
xpr = StringVar(fbox); xpr.set("100")
ypr = StringVar(fbox); ypr.set("100")
xpx = StringVar(fbox); xpx.set(str(x))
ypx = StringVar(fbox); ypx.set(str(y))
Label(fbox,text="X%",width=5).grid(row=1,column=1)
def update1():
    xs = float(xpr.get() and xpr.get() or 0)/100
    xpx.set(str(int(xs*ix)))
xpercent = Entry(fbox,width=10,textvariable=xpr,validate="key",validatecommand=update1)
xpercent.grid(row=1,column=2)
Label(fbox,text="Y%",width=5).grid(row=2,column=1)
ypercent = Entry(fbox,width=10,textvariable=ypr)
ypercent.grid(row=2,column=2)

Label(fbox,text="Xpx",width=5).grid(row=1,column=3)
Entry(fbox,width=10,textvariable=xpx).grid(row=1,column=4)
Label(fbox,text="Ypx",width=5).grid(row=2,column=3)
Entry(fbox,width=10,textvariable=ypx).grid(row=2,column=4)

def applycom():
    resizebox.quit()
Button(fbox,text="OK",command=applycom,width=10).grid(row=3,column=2)
def exitcom(): resizebox.quit()
Button(fbox,text="Cancel",command=exitcom,width=10).grid(row=3,column=4)

percentupdate = pxupdate = False
"""def updatebypercent(event):
    global percentupdate
    percentupdate = True
xpercent.bind("<Key>",updatebypercent,add='+')
ypercent.bind("<Key>",updatebypercent,add='+')
def connectentries(event):
    global percentupdate
    global pxupdate
    if percentupdate:
        xs = float(xpr.get() and xpr.get() or 0)/100
        ys = float(ypr.get() and ypr.get() or 0)/100
        xpx.set(str(int(xs*ix))); ypx.set(str(int(ys*iy)))
        percentupdate = False
resizebox.register(connectentries)"""

resizebox.mainloop()
